home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Periodicals / develop / develop 7 code / QuickTime / SimpleInMovies / SimpleInMovies.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-13  |  21.2 KB  |  800 lines  |  [TEXT/MPS ]

  1.  
  2. /*     
  3. SimpleInMovies
  4.  
  5. Sample programs demonstrating how to open and display
  6. QuickTime™ Movies.
  7.  
  8. SimpleInMovies.c file contains the code for the main loop and the
  9. routines that open and display movies in a window.
  10.  
  11. Each window is associated with a movie and an instance of the movie
  12. controller. There are menu equivalents for movie controller commands
  13. to show how to interact with the controller.
  14.  
  15. Guillermo A. Ortiz
  16. Macintosh Developer Technical Support
  17.  
  18. 07/17/91 Editing code goes in for the first time
  19. 08/07/91 Added code to put cuts into the scrap when being switched in/out.
  20.  
  21. */
  22.  
  23. /* Interface changes:
  24. 08/06/91 -- OpenMovieFile lost the parameter.
  25. 12/03/91 -- Using MCGetControllerInfo to adjust menus.
  26. */
  27.  
  28. #include <SimpleInMovie.h>
  29.  
  30. void myGetMoov(void);
  31. OSErr MakeNewMovie(void);
  32. void DoIdleStuff(void);
  33. OSErr CreateMinMovie(Movie *);
  34.  
  35. extern void ChangeMooVState(void);
  36. extern void ChangeMooVSound(void);
  37. extern void NextMooVFrame(void);
  38. extern void PrevMooVFrame(void);
  39. extern void SetMovieLoop(short);
  40.  
  41. extern void DoEnableEditing(void);
  42. extern void    DoUndoMovie(void);
  43. extern void    DoCutMovie(void);
  44. extern void DoCopyMovie(void);
  45. extern void DoPasteMovie(void);
  46. extern void DoClearMovie(void);
  47. extern void DoSelectAll(void);
  48. extern void DoScrapStuff(Boolean toScrap);
  49.  
  50. extern Boolean CreateOneWindow(Movie, StandardFileReply, short, short);
  51. extern Boolean IsAppWindow(WindowPtr);
  52. extern Boolean    DisposeAllWindows(void);
  53. extern Boolean    DisposeOneWindow(WindowPtr, short);
  54. extern Boolean DoSave(short);
  55.  
  56. extern Boolean IsPlayerEvent(WindowPtr, EventRecord *);
  57. extern Handle    GetAppResource(ResType,short, OSErr *);
  58.  
  59. void AdjustMenus(void);
  60.  
  61. extern void DoGet1MoviePict(void);
  62. extern void DoGetTrackPicts(void);
  63.  
  64. extern void PresentStyleDialog ( void );
  65. extern void PrintPoster( void);
  66. extern void PrintTerminate(void);
  67. extern void PrintInit(void);
  68.  
  69. extern void    pstrcat(char *, char *);
  70. extern void    pstrcpy(char *, char *);
  71. /*
  72.  * Global Data objects, used by routines external to main().
  73.  */
  74. MenuHandle        MyMenus[menuCount];     /* The menu handles */
  75. Boolean         DoneFlag;                /* Becomes TRUE when File/Quit chosen */
  76. short            gUntitledCount=1;
  77.  
  78. Boolean gMoviesInited, wasChanged;
  79. long timeOfMovie = 0;
  80.  
  81. Component movieControllerComponent;
  82.  
  83. extern void _DataInit();
  84. extern Movie cuts;                    /* local scrappy movie */
  85. /*******************************************************************************************
  86.  *******************************************************************************************/
  87. /* Initialize the movie toolbox, call InitMovies to let the toolbox know
  88.    of this app, get controller; if something fails set flag to get out of here */
  89.    
  90. void InitMovieStuff()
  91. {
  92. ComponentDescription controllerDescriptor;
  93. extern Boolean        DoneFlag;
  94. long version;
  95.  
  96. /* We have to fill in the fields for the player descriptor in order to get the
  97.    standard movie controller component */
  98.     controllerDescriptor.componentType = 'play';
  99.     controllerDescriptor.componentSubType = 0;
  100.     controllerDescriptor.componentManufacturer = 0;
  101.     controllerDescriptor.componentFlags = 0;
  102.     controllerDescriptor.componentFlagsMask = 0;
  103.  
  104.     /* we'll use gMoviesInited as a flag for everything, a false value
  105.        indicates that the movie toolbox or the standard player couldn't be initialized */
  106.     gMoviesInited = false;                /* so pessimistic            */
  107.     
  108.     if (!(Gestalt(gestaltQuickTime, &version)))
  109.       if ( ! (EnterMovies()) ) 
  110.         if ( movieControllerComponent = FindNextComponent((Component) 0, 
  111.             &controllerDescriptor) )                 /* no error means we are OK */
  112.           gMoviesInited = true;            /* good!                    */
  113.  
  114.     if (!gMoviesInited) {
  115.       Alert(rBadMooviesALRT,nil);     /* inform user                    */
  116.       DoneFlag = true;                /* we are bailing out            */
  117.     }
  118. }
  119. /*******************************************************************************************
  120.  *******************************************************************************************/
  121.  
  122. Boolean CheckSystem()
  123. {
  124. long systemVersion;
  125. Boolean notSeven = true;
  126.  
  127.     if (!Gestalt(gestaltSystemVersion, &systemVersion) ) {
  128.       if (systemVersion >= 0x0700) 
  129.         notSeven = false;
  130.     }
  131.     if (notSeven) {
  132.       Alert(rNotSeven,nil);     /* inform user                    */
  133.       DoneFlag = true;                /* we are bailing out            */
  134.     }
  135.     return (notSeven);
  136. }
  137. void DoInits()
  138. {
  139.     UnloadSeg((Ptr) _DataInit);        /* note that _DataInit must not be in Main! */
  140.  
  141.     /*
  142.      * Initialization traps
  143.      */
  144.     InitGraf(&qd.thePort); 
  145.     InitFonts();
  146.     FlushEvents(everyEvent, 0);
  147.     InitWindows();
  148.     InitMenus();
  149.     TEInit();
  150.     InitDialogs(nil); 
  151.     InitCursor();
  152.     
  153.     MaxApplZone();
  154.     if (!CheckSystem() )
  155.       InitMovieStuff();
  156.     PrintInit();
  157. }
  158. /*******************************************************************************************
  159.  *******************************************************************************************/
  160.  
  161. /* Main contains the event loop, we dispatch here to serve the different
  162.    events, movie fans should pay attention to the way controller events are
  163.    handled when comming through the loop.
  164. */
  165. short main()
  166. {
  167.     Rect                    screenRect;
  168.     Rect                    dragRect;
  169.     EventRecord             myEvent;
  170.     WindowPtr                theActiveWindow;
  171.     WindowPtr                whichWindow;
  172.     Boolean                 Result;
  173.     extern void             setupMenus();
  174.     extern void             doCommand();
  175.     DocRecHandle             wHndl;
  176.     Boolean                    inBackground = false;
  177.  
  178.     DoInits();
  179.     
  180.     setupMenus();            
  181.     
  182.     screenRect = qd.screenBits.bounds;
  183.     SETRECT(&dragRect, 4, 20 + 4, screenRect.right-4, screenRect.bottom-4);
  184.         
  185.     DoneFlag = false;
  186.     
  187.     /* ************************************************************** */
  188.     
  189.     for ( ;; ) {
  190.         if (DoneFlag) {
  191.             /*
  192.              * Quit has been requested, by the File/Quit menu, or perhaps
  193.              * by a fatal error somewhere else (missing resource, etc).
  194.              * Here we put up a Save Changes? DLOG, which also
  195.              * allows the Cancel buttion to set DoneFlag to false.
  196.              */
  197.             if (!DisposeAllWindows())    /* this releases stdplayer instances */
  198.               DoneFlag = false;            /* user pressed cancel maybe? */
  199.             else 
  200.               break;        /* from main event loop */
  201.         }
  202.         /*
  203.          * Main Event tasks:
  204.          */
  205.         SystemTask();
  206.         theActiveWindow = FrontWindow();        /* Used often, avoid repeated calls */
  207.  
  208.         Result = GetNextEvent(everyEvent, &myEvent);
  209.  
  210. /* When the movie controller is being used it is a good idea to let it handle the
  211.    updates for movies; to accomplish this the controller has to be given time every
  212.    pass through the event loop. If the controller handles the event then roll again
  213.    if not then we let the normal loop code take care of it.
  214. */
  215.         if (IsPlayerEvent(*(WindowPtr*) WindowList, &myEvent) ) 
  216.           continue;
  217.         if (Result ) { 
  218.           
  219.         switch (myEvent.what) {
  220.             case mouseDown:
  221.                     switch (FindWindow(myEvent.where, &whichWindow)) {
  222.                     case inSysWindow:
  223.                         SystemClick(&myEvent, whichWindow);
  224.                         break;
  225.  
  226.                     case inMenuBar:
  227.                         {
  228.                         doCommand(MenuSelect(myEvent.where));
  229.                         }
  230.                         break;
  231.  
  232.                     case inDrag:
  233.                         DragWindow(whichWindow, myEvent.where, &dragRect);
  234.                         break;
  235.  
  236.                 case inGoAway:
  237.                     if (TrackGoAway(whichWindow, myEvent.where)) {
  238.                         DisposeOneWindow(whichWindow, closeMovie);
  239.                     }
  240.                     break;
  241.  
  242.                     case inGrow:
  243.                         /* There is no grow box. (Fall through) */
  244.  
  245.                     case inContent:
  246.                       if (whichWindow != theActiveWindow) {
  247.                             SelectWindow(whichWindow);
  248.                         }
  249.                     default:
  250.                         break;
  251.                     }/*endsw FindWindow*/
  252.                     break;
  253.  
  254.             case keyDown:
  255.             case autoKey:
  256.                     if (myEvent.modifiers & cmdKey) {
  257.                         AdjustMenus();
  258.                         doCommand(MenuKey(myEvent.message & charCodeMask));
  259.                     }
  260.                 break;
  261.                 
  262.             case activateEvt:
  263.                 break;
  264.  
  265.             case updateEvt:
  266.                 if ( IsAppWindow((WindowPtr) myEvent.message )) {
  267.                     BeginUpdate((WindowPtr) myEvent.message );
  268.                     SetPort((WindowPtr) myEvent.message);
  269.                     EraseRect(&(((GrafPtr) myEvent.message)->portRect));
  270.                     if (wHndl = (DocRecHandle)GetWRefCon((WindowPtr) myEvent.message) ) {
  271.                         UpdateMovie((*wHndl)->wMovie); 
  272.                     }
  273.                     EndUpdate((WindowPtr) myEvent.message );
  274.                 }
  275.             break;
  276.             case osEvt:
  277.               switch ((myEvent.message >> 24) & 0x0FF) {
  278.                     /* Must logical and with 0x0FF to get only low byte. */
  279.  
  280.                 case mouseMovedMessage:
  281.                     break;
  282.  
  283.                 case suspendResumeMessage:
  284.                     inBackground = !(myEvent.message & resumeFlag);
  285.                       DoScrapStuff(inBackground);
  286.                     break;
  287.             }
  288.             break;
  289.  
  290.             default:
  291.                 break;
  292.  
  293.         }/*endsw myEvent.what*/
  294.       AdjustMenus();
  295.     }
  296.     else {                 /* this is the place where you normally would call your idle routine */
  297. /*      DoIdleStuff(); */    /* to activate movies; in this case we let the standard controller     */
  298.     }                    /* do the idle stuff                                                 */
  299.  
  300.     }/*endfor Main Event loop*/
  301.     PrintTerminate();
  302.     ExitMovies();        /* make sure all references to this app are removed */
  303.     
  304.     return 0;        /* Return from main() to allow C runtime cleanup */
  305. }
  306.  
  307. /*******************************************************************************************
  308.  *******************************************************************************************/
  309.  
  310.  /* standard Macintosh routines */
  311.  
  312. void setupMenus()
  313. {
  314.     extern        MenuHandle    MyMenus[];
  315.     register    MenuHandle    *pMenu;
  316.  
  317.     /*
  318.      * Set up the desk accessories menu.
  319.      * The "About Sample..." item, followed by a grey line,
  320.      * is presumed to be already in the resource.  We then
  321.      * append the desk accessory names from the 'DRVR' resources.
  322.      */
  323.     MyMenus[appleMenu] = GetMenu(appleID);
  324.     AddResMenu(MyMenus[appleMenu], (ResType) 'DRVR');
  325.     /*
  326.      * Now the  menus.
  327.      */
  328.  
  329.     MyMenus[fileMenu] = GetMenu(fileID);
  330.     MyMenus[editMenu] = GetMenu(editID);
  331.     MyMenus[moovieMenu] = GetMenu(moovieID);
  332.     MyMenus[pictsMenu] = GetMenu(pictsID);
  333.  
  334.     /*
  335.      * Now insert all of the application menus in the menu bar.
  336.      *
  337.      */
  338.     for (pMenu = &MyMenus[0]; pMenu < &MyMenus[menuCount]; ++pMenu) {
  339.         InsertMenu(*pMenu, 0);
  340.     }
  341.  
  342.     DrawMenuBar();
  343.  
  344.     return;
  345. }
  346.  
  347. /*
  348.  * Display the Sample Application dialog.
  349.  * We insert two static text items in the DLOG:
  350.  *        The author name
  351.  *        The source language
  352.  * Then wait until the OK button is clicked before returning.
  353.  */
  354. void showAboutMeDialog()
  355. {
  356.     GrafPtr     savePort;
  357.     DialogPtr    theDialog;
  358.     short        itemType;
  359.     Handle        itemHdl;
  360.     Rect        itemRect;
  361.     short        itemHit;
  362.  
  363.     GetPort(&savePort);
  364.     theDialog = GetNewDialog(aboutMeDLOG, nil, (WindowPtr) -1);
  365.     SetPort(theDialog);
  366.  
  367.     GetDItem(theDialog, authorItem, &itemType, &itemHdl, &itemRect);
  368.     SetIText(itemHdl, "\pGuillermo A. Ortiz, MacDTS");
  369.     GetDItem(theDialog, languageItem, &itemType, &itemHdl, &itemRect);
  370.     SetIText(itemHdl, "\pC");
  371.  
  372.     do {
  373.         ModalDialog(nil, &itemHit);
  374.     } while (itemHit != okButton);
  375.  
  376.     CloseDialog(theDialog);
  377.  
  378.     SetPort(savePort);
  379.     return;
  380. }
  381. /*
  382.  * Process mouse clicks in menu bar
  383.  */
  384.  
  385. Boolean hilited = false;
  386. void doCommand(mResult)
  387.     long    mResult;
  388. {
  389.     long                 theMenu, theItem;
  390.     char                daName[256];
  391.     GrafPtr             savePort;
  392.     extern MenuHandle    MyMenus[];
  393.     extern Boolean        DoneFlag;
  394.     extern void         showAboutMeDialog();
  395.  
  396.     theItem = LOWORD(mResult);
  397.     theMenu = HIWORD(mResult);        /* This is the resource ID */
  398.  
  399.     switch (theMenu) {
  400.         case appleID:
  401.             if (theItem == aboutMeCommand) {
  402.                 showAboutMeDialog();
  403.             } else {
  404.                 GetItem(MyMenus[appleMenu], theItem, daName);
  405.                 GetPort(&savePort);
  406.                 (void) OpenDeskAcc(daName);
  407.                 SetPort(savePort);
  408.             }
  409.             break;
  410.  
  411.         case fileID:
  412.             switch (theItem) {
  413.                 case newMovie:
  414.                      MakeNewMovie();
  415.                      break;
  416.                 case loadMovie:
  417.                      {
  418.                         myGetMoov();                        /* selects MooVie */
  419.                         break;
  420.                      }
  421.                 case closeMovie:
  422.                     DisposeOneWindow(FrontWindow(), closeMovie);
  423.                     break;
  424.                 case saveMovie:
  425.                     DoSave(saveMovie);
  426.                     break;
  427.                 case saveMovieAs:
  428.                     DoSave(saveMovieAs);
  429.                     break;
  430.                 case printCommand:
  431.                     PrintPoster();
  432.                     break;
  433.                 case pageCommand:
  434.                     PresentStyleDialog();
  435.                     break;
  436.                 case quitCommand:
  437.                     DoneFlag = true;            /* Request exit */
  438.                     break;
  439.                 default:
  440.                     break;
  441.             }
  442.             break;
  443.  
  444.         case editID:
  445.             /*
  446.              * If this is for a 'standard' edit item,
  447.              * run it through SystemEdit first.
  448.              * SystemEdit will return FALSE if it's not a system window.
  449.              */
  450.             if ((theItem <= selectAllCommand) && SystemEdit(theItem-1)) {
  451.                 break;
  452.             }
  453.             /* We will use the standard controller to do all the movie editing stuff     */
  454.             /* all this commands will affect the front most window only                 */
  455.             switch (theItem) {
  456.                 case undoCommand:
  457.                   DoUndoMovie();
  458.                   break;
  459.                 case cutCommand:
  460.                   DoCutMovie();
  461.                   break;
  462.                 case copyCommand:
  463.                   DoCopyMovie();
  464.                   break;
  465.                 case pasteCommand:
  466.                   DoPasteMovie();
  467.                   break;
  468.                 case clearCommand:
  469.                   DoClearMovie();
  470.                   break;
  471.                 case selectAllCommand:
  472.                   DoSelectAll();
  473.                   break;
  474.                 default:
  475.                     break;
  476.             } /*endsw theItem*/
  477.             break;
  478.  
  479.         case moovieID:
  480.             switch (theItem) {
  481.                 case stplayMovie:
  482.                      {
  483.                         ChangeMooVState();                        /* stop-start movie */
  484.                         break;
  485.                      }
  486.                 case soundMovie:
  487.                      {
  488.                         ChangeMooVSound();                        /* toggles sound */
  489.                         break;
  490.                      }
  491.                 case advFrMovie:
  492.                      {
  493.                         NextMooVFrame();                        /* advances one frame */
  494.                         break;
  495.                      }
  496.                 case revFrMovie:
  497.                      {
  498.                         PrevMooVFrame();                        /* moves one frame back */
  499.                         break;
  500.                      }
  501.                 case loopMovie:
  502.                      {
  503.                         SetMovieLoop(theItem);                    /* sets playback to loop */
  504.                         break;
  505.                      }
  506.                 case weirdLoopMovie:
  507.                      {
  508.                         SetMovieLoop(theItem);                    /* Loop back and forth */
  509.                         break;
  510.                      }
  511.                 case editMovie:
  512.                     {
  513.                         DoEnableEditing();
  514.                         break;
  515.                     }
  516.                 default:
  517.                     break;
  518.                 
  519.             }
  520.             break;
  521.  
  522.         case pictsID:
  523.             switch (theItem) {
  524.                 case getTrackPicts:
  525.                      {
  526.                         DoGetTrackPicts();                
  527.                         break;
  528.                      }
  529.                 case get1MoviePict:
  530.                      {
  531.                         DoGet1MoviePict();        
  532.                         break;
  533.                      }
  534.                 default:
  535.                     break;
  536.                 
  537.             }
  538.             break;
  539.  
  540.         default:
  541.             break;
  542.  
  543.     }/*endsw theMenu*/
  544.  
  545.     HiliteMenu(0);
  546.  
  547.     return;
  548. }
  549.  
  550.  
  551. /*******************************************************************************************
  552.  *******************************************************************************************/
  553. /* the following code creates a new movie, it comes empty but you could use pastes to
  554.    add stuff to it.
  555.    
  556. */
  557. OSErr MakeNewMovie(void)
  558. {
  559. OSErr theErr;
  560. Movie newMoov;
  561. StandardFileReply fake;
  562. Str255 s1,s2="\pUntitled # ";
  563.  
  564.     if (theErr = CreateMinMovie(&newMoov)) {
  565.       DebugStr("\pmovie creation failed");    
  566.       return (theErr);
  567.     }
  568.     
  569.     NumToString(gUntitledCount,s1); /* get current untitled count     */
  570.     gUntitledCount++;                /* then bump it                    */
  571.     
  572.     pstrcat (s2, s1);
  573.     pstrcpy (fake.sfFile.name, s2);
  574.     
  575.     fake.sfFile.vRefNum = kInvalVRefNum;
  576.     
  577.     CreateOneWindow(newMoov, fake, kNoFileOpen, kNoResourceYet);
  578.     ClearMovieChanged(newMoov);
  579. }
  580.  
  581. /*******************************************************************************************
  582.  *******************************************************************************************/
  583.  
  584. void myGetMoov(void)
  585. {
  586. SFTypeList myFileTypes = {'MooV'};
  587. StandardFileReply reply;
  588. Point where = {20,20};
  589.  
  590. short    saveResFile, movieResFile;
  591. OSErr err;
  592.  
  593. Rect    moovBox;
  594. Movie moov;
  595. short resID = 0;
  596.  
  597.  
  598. saveResFile = CurResFile();
  599. StandardGetFilePreview(0L, 1, myFileTypes, &reply);
  600.  
  601. if (reply.sfGood)
  602.   { 
  603.  
  604.  
  605. /* we will open the file with read permission and ask for no MoviesDataRef 
  606.    which is necessary when adding stuff to a movie */
  607. /****** OpenMovieFile lost the last parameter 08/06/91 
  608.     if ( OpenMovieFile(&(reply.sfFile), &movieResFile,fsRdPerm, nil) ) {
  609. */
  610.     if ( OpenMovieFile(&(reply.sfFile), &movieResFile,fsRdWrPerm) ) {
  611.         SysBeep(10);        /* cheap way of saying 'I couldn't open the file     */
  612.         return;                /* and go back                                        */
  613.     }
  614.     else { /* the deal is that a file is selected but you do not know the moov id; 
  615.             so we pass 0 for id to get the first moov resource available 
  616.             (we do nothing with the returned ID, we could pass nil), nil for name pointer
  617.             and 0 for flags since I want a complete movie and don't want it to be active     */
  618.  
  619.       if ( err = NewMovieFromFile( &moov, movieResFile, &resID, nil, 0, &wasChanged) ) {
  620.         DebugStr("\pCould not get the moov ");
  621.       }
  622. /* We allow for editing files so we don't close the files after getting the movie.
  623.    This change reflects in the permision for OpenMovieFile above.
  624.     CloseMovieFile(movieResFile);
  625. */
  626.     }
  627.  
  628.     if ( !err ) { 
  629.         GetMovieBox(moov,&moovBox); /* Use the movie box to resize window */
  630.         OffsetRect(&moovBox, -moovBox.left, -moovBox.top);  /* force topleft to zero */
  631.         SetMovieBox(moov, &moovBox);
  632.  
  633.         CreateOneWindow(moov, reply, movieResFile, resID);
  634.  
  635.         SetMovieActive(moov,true);  /* we got the movie inactive */
  636.         if (err = GetMoviesError() )
  637.             DebugStr("\perror after SetMovieActive"); 
  638.  
  639. /* When using the controller you want to make all calls that affect the state of the
  640.    movie through the controller action calls; if you don't the controller could go
  641.    off sync. For example, instead of calling StartMovie, you call
  642.    MCDoAction((*DocHandle)->wPlayer, mcActionPlay, (Ptr)0x00010000) in order to
  643.    set the movie in motion. Check the routine CreateOneWindow in SimpleInWindows.c.
  644.  
  645.         if (! err) {
  646.             StartMovie(moov);                    **** if we do this then the movie will be
  647.             if (err = GetMoviesError() )        **** playing but the start button will show 
  648.                 DebugStr("\perror after startmovie");
  649.         }
  650. */
  651.     }
  652.   }
  653. UseResFile(saveResFile); /* Just in case */
  654.  
  655. }
  656.  
  657.  
  658. /*******************************************************************************************
  659.  *******************************************************************************************/
  660. /* If an app is not using the standard controller it has to call MoviesTask in order to     */
  661. /* let the Movie Toolbox animate the movies. In this sample DoIdleStuff is not called        */
  662. void DoIdleStuff(void)
  663. {
  664. OSErr err;
  665. WindowPtr window;
  666.  
  667.   if (window = FrontWindow()) { /* don't bother if no movies to play */
  668.     MoviesTask((Movie) 0, 500);    /* but since we have one service all */    
  669.     if (err = GetMoviesError() )
  670.       DebugStr("\pafter MoviesTask");         
  671.   }
  672. }
  673.  
  674.  
  675. /*******************************************************************************************
  676.  *******************************************************************************************/
  677.  
  678. /* this enables/disables menu items as the state of the current front most
  679.    movie requires. 
  680. */
  681. void AdjustMenus()
  682. {
  683. WindowPtr window;
  684. DocRecHandle wHndl;
  685. long mcInfo;
  686.  
  687.   if (window = FrontWindow()) { /* don't bother if no movies to play */
  688.     if (IsAppWindow(window) && (wHndl = (DocRecHandle)GetWRefCon(window)) ) {
  689.       EnableItem(MyMenus[moovieMenu],nil);
  690.       EnableItem(MyMenus[pictsMenu],nil);
  691.       EnableItem(MyMenus[editMenu],nil);
  692.       DrawMenuBar();
  693.       
  694.       if ( MCGetControllerInfo((*wHndl)->wPlayer, &mcInfo) )
  695.         DebugStr("\pCould not get controller info");
  696.     
  697.     /* Check Edit menu items */
  698.       if ( mcInfo & mcInfoEditingEnabled) { /* fix edit menu items */
  699.         if ( mcInfo & mcInfoUndoAvailable)
  700.           EnableItem(MyMenus[editMenu],undoCommand);
  701.         else
  702.           DisableItem(MyMenus[editMenu],undoCommand);
  703.           
  704.         if ( mcInfo & mcInfoCutAvailable)
  705.           EnableItem(MyMenus[editMenu],cutCommand);
  706.         else
  707.           DisableItem(MyMenus[editMenu],cutCommand);
  708.           
  709.         if ( mcInfo & mcInfoCopyAvailable)
  710.           EnableItem(MyMenus[editMenu],copyCommand);
  711.         else
  712.           DisableItem(MyMenus[editMenu],copyCommand);
  713.           
  714.         if ( mcInfo & mcInfoClearAvailable)
  715.           EnableItem(MyMenus[editMenu],clearCommand);
  716.         else
  717.           DisableItem(MyMenus[editMenu],clearCommand);
  718.           
  719.         if ( cuts /* mcInfo & mcInfoPasteAvailable */)
  720.           EnableItem(MyMenus[editMenu],pasteCommand);
  721.         else
  722.           DisableItem(MyMenus[editMenu],pasteCommand);
  723.           
  724.         EnableItem(MyMenus[editMenu],selectAllCommand); /* and last */
  725.           
  726.       }
  727.       else
  728.         DisableItem(MyMenus[editMenu],nil); /* no editing happening */
  729.     
  730.     
  731.     /* Check Movie menu items */
  732.     /* fix sound item according to front most window */
  733.       if ( mcInfo & mcInfoHasSound ) {
  734.         EnableItem(MyMenus[moovieMenu],soundMovie);
  735.         if ( GetMovieVolume((*wHndl)->wMovie) > 0) { /* fix sound menu item*/
  736.           SetItem(MyMenus[moovieMenu], soundMovie,"\pSound Off");
  737.         }
  738.         else  { 
  739.           SetItem(MyMenus[moovieMenu], soundMovie,"\pSound On");
  740.         }
  741.       }
  742.       else
  743.         DisableItem(MyMenus[moovieMenu],soundMovie);
  744.         
  745.       if ( mcInfo & mcInfoEditingEnabled) { /* fix edit menu item*/
  746.         SetItem(MyMenus[moovieMenu], editMovie,"\pDisable Edits");
  747.       }
  748.       else  { 
  749.         SetItem(MyMenus[moovieMenu], editMovie,"\pEnable Edits");
  750.       }
  751.       
  752.       if ( mcInfo & mcInfoIsPlaying ) {/* fix motion menu item */
  753.         SetItem(MyMenus[moovieMenu], stplayMovie,"\pStop Movie");
  754.       }
  755.       else  { 
  756.         SetItem(MyMenus[moovieMenu], stplayMovie,"\pStart Movie");
  757.       }
  758.  
  759.       /* loop menu items */
  760.       CheckItem(MyMenus[moovieMenu], loopMovie,mcInfo & mcInfoIsLooping);
  761.       CheckItem(MyMenus[moovieMenu], weirdLoopMovie,mcInfo & mcInfoIsInPalindrome);
  762.       
  763.       EnableItem(MyMenus[fileMenu],closeMovie);    
  764.       EnableItem(MyMenus[fileMenu],saveMovie);    
  765.       EnableItem(MyMenus[fileMenu],saveMovieAs);    
  766.     }
  767.   }
  768.   else {
  769.     DisableItem(MyMenus[fileMenu],closeMovie);
  770.     DisableItem(MyMenus[fileMenu],saveMovie);
  771.     DisableItem(MyMenus[fileMenu],saveMovieAs);
  772.     DisableItem(MyMenus[editMenu],nil);
  773.     DisableItem(MyMenus[moovieMenu],nil);
  774.     DisableItem(MyMenus[pictsMenu],nil);
  775.  }
  776. }
  777.  
  778. /*******************************************************************************************
  779.  *******************************************************************************************/
  780.  
  781. OSErr CreateMinMovie(moovPtr)
  782. Movie *moovPtr;
  783. {
  784. Movie localMovie;
  785. OSErr theErr;
  786.  
  787.     localMovie = NewMovie(newMovieActive /* newMovieFlags */);
  788.     if (theErr = GetMoviesError() ) {
  789.       *moovPtr = nil;
  790.       DebugStr("\pCould not create movie");
  791.     }
  792.     else
  793.       *moovPtr = localMovie;
  794.     return (theErr);
  795. }
  796.  
  797. /*******************************************************************************************
  798.  *******************************************************************************************/
  799.  
  800.